<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../../plugin/layui/css/layui.css">
    <link rel="stylesheet" href="../../../plugin/ztree/css/metroStyle/metroStyle.css">
    <script type="text/javascript" src="../../../plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="../../../plugin/layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../../plugin/ztree/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="../../../plugin/ztree/js/jquery.ztree.excheck.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../../plugin/tools/tool.js"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form layui-form-pane" style="margin-left: 20px;">
        <div style="width:100%;height:400px;overflow: auto;">
            <div class="layui-form-item" style="text-align: center;width: 100%;padding-top:10px;">
                <input lay-filter="type" type="radio" name="sex" value="0" title="需求" checked>
                <input lay-filter="type" type="radio" name="sex" value="1" title="缺陷" >
                <input lay-filter="type" type="radio" name="sex" value="2" title="任务">
            </div>
            <div style="padding-right: 15px;padding-left: 15px;">
                <table id="issueList" class="layui-hide" lay-filter="issueList"></table>
            </div>
        </div>
        <div style="width: 100%;height: 55px;background-color: white;border-top:1px solid #e6e6e6;position: fixed;bottom: 1px;margin-left:-20px;">
            <div class="layui-form-item" style=" float: right;margin-right: 30px;margin-top: 8px">
                <button id="ok" class="layui-btn layui-btn-normal" lay-filter="addItem" lay-submit>
                    增加
                </button>
                <button class="layui-btn layui-btn-primary" id="close">
                    取消
                </button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer', 'layedit'], function () {
        $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;
        var data = window.parent.data;
        var type = 0;

        form.render();

        // 单选按钮切换
        form.on('radio(type)', function(data){
            type = data.value;
            var url = '';
            if(type == '0'){
                url = '../../../pdms/requirement/selectList';
            }else if(type == '1'){
                url = '../../../pdms/bug/selectList';
            }else if(type == '2'){
                url = '../../../pdms/task/selectList';
            }
            layui.table.reload('issueList',{
                url:url
            });
        });

        //方法级渲染
        layui.table.render({
            id: 'issueList',
            elem: '#issueList'
            , url: '../../../pdms/requirement/selectList'
            , cols: [[
                {checkbox: true, fixed: true, width: '5%'}
                , {field: 'name', title: '问题名称', width: '20%', sort: true}
                , {field: 'content', title: '问题内容', width: '20%', sort: true}
                , {field: 'createDateText', title: '创建时间', width: '20%', sort: true}
                , {field: 'statusText', title: '状态', width: '10%', sort: true}
            ]]
            , page: true
            , height: 300
            , done: function(res, curr, count){
                /*$("[tag='name']").click(function () {
                    addIssue();
                });*/
            }
        });

        $('#close').click(function (){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });

        //监听提交
        form.on('submit(addItem)', function (data) {
            var checkStatus = layui.table.checkStatus('issueList'); //idTest 即为基础参数 id 对应的值
            var dataList = checkStatus.data;
            if(dataList.length == 0){
                layer.msg('请至少选择一条数据');
                return false;
            }

            var items = new Array();
            for(var i = 0 ; i< dataList.length;i++){
                items.push({id:dataList[i].id});
            }

            $.post('../../../pdms/iteration/addIssue',{id:parent.data.id,type:type,items:JSON.stringify(items)},function(data){
                layer.msg('添加成功');
                parent.layui.table.reload('issueList'); // 刷新表格
                /*layer.msg('添加成功');
                // 关闭窗口
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);*/
            });

            return false;
        });

    });
</script>
</body>

</html>
